﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 游戏平台原型
{
    class User
    {
        static public User user;
        public string currentusername;
        public long currentuserno;
        public Room currentroom;
        public Panel currentpanel;
        public User(string username)
        {
            currentusername = username;
            currentuserno = name2no(currentusername);
        }
        static public long name2no(string name)
        {
            Connection conn = new Connection();
            conn.sql("select id from userinfo where username='" + name + "'");
            conn.dr.Read();
            return conn.dr.GetInt64(0);
        }
        static public string no2name(long no)
        {
            Connection conn = new Connection();
            conn.sql("select username from userinfo where id='" + no + "'");
            conn.dr.Read();
            return conn.dr.GetString(0);
        }
        public void loginin(long userid)
        {
            Lobby.Lobby1.onlinelist.ListInsert(userid);
        }
        public void enterroom(long userid,long roomid)
        {
            currentroom = Lobby.Lobby1.Seekroom(roomid);
            currentroom.onlinelist.ListInsert(userid);
        }
        public void enterpanel(long userid, int panelid)
        {
            currentpanel = currentroom.panel[panelid];
            currentpanel.onlinelist.ListInsert(userid);
        }
        public void exitpanel(long userid, int panelid)
        {
            currentpanel = null;
            currentpanel.onlinelist.ListDelete(userid);
        }
        public void exitroom(long userid, long roomid)
        {
            currentroom = null;
            currentroom.onlinelist.ListDelete(userid);
        }
        public void loginout(long userid)
        {
            Lobby.Lobby1.onlinelist.ListDelete(userid);
        }
    }
}
